# Contributor: Matt Smith <mcs@darkregion.net>
# Maintainer:  Matt Smith <mcs@darkregion.net>
pkgname=pdnsd
pkgver=1.2.9a
_realver=$pkgver-par
pkgrel=5
pkgdesc="A proxy DNS server with permanent caching"
url="http://members.home.nl/p.a.rombouts/pdnsd/"
arch="all"
license="GPL"
depends=
depends_dev=
makedepends="$depends_dev linux-headers"
install="$pkgname.pre-install"
subpackages="$pkgname-doc"
pkgusers="pdnsd"
pkggroups="pdnsd"
source="http://members.home.nl/p.a.rombouts/pdnsd/releases/pdnsd-$pkgver-par.tar.gz
	pdnsd.initd
	pdnsd.confd
	pdnsd.conf
	"

_builddir="$srcdir"/$pkgname-$pkgver
prepare() {
	local i
	cd "$_builddir"
	for i in $source; do
		case $i in
		*.patch) msg $i; patch -p1 -i "$srcdir"/$i || return 1;;
		esac
	done
}

build() {
	cd "$_builddir"
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--infodir=/usr/share/info \
		--localstatedir=/var \
		--enable-ipv6 \
		--with-random-device=/dev/urandom \
		--enable-tcp-subseq \
		|| return 1
	make || return 1
}

package() {
	cd "$_builddir"
	make DESTDIR="$pkgdir" install || return 1

	install -m755 -D "$srcdir"/$pkgname.initd \
		"$pkgdir"/etc/init.d/$pkgname || return 1
	install -m644 -D "$srcdir"/$pkgname.confd \
		"$pkgdir"/etc/conf.d/$pkgname || return 1
	install -m644 -D "$srcdir"/$pkgname.conf \
		"$pkgdir"/etc/$pkgname.conf || return 1

	chown -R pdnsd "$pkgdir"/var/cache/pdnsd || return 1
	sed -ri 's/([    ]*run_as=)"nobody";/\1"pdnsd";/' \
		"$pkgdir"/etc/pdnsd.conf.sample || return 1
	sed -ri '/pid_file/d' "$pkgdir"/etc/pdnsd.conf.sample || return 1
	sed -ri '/query_method/d' "$pkgdir"/etc/pdnsd.conf.sample || return 1
}

doc() {
	mkdir -p "$subpkgdir"/usr/share/doc/$pkgname/html || return 1
	mkdir -p "$subpkgdir"/usr/share/doc/$pkgname/txt || return 1
	mkdir -p "$subpkgdir"/usr/share/$pkgname/contrib || return 1

	# /usr/share/{man,doc/$pkgname}
	cp -a "$pkgdir"/usr/share/ "$subpkgdir"/usr/ || return 1
	rm -rf "$pkgdir"/usr/share/ || return 1
	_docs="AUTHORS COPYING COPYING.BSD ChangeLog ChangeLog.old \
		NEWS README README.par README.par.old THANKS TODO"
	for _doc in $_docs; do
		cp "$_builddir"/$_doc "$subpkgdir"/usr/share/doc/$pkgname/ \
			|| return 1
	done
	cp -R "$_builddir"/doc/html/* \
		"$subpkgdir"/usr/share/doc/$pkgname/html/ || return 1
	cp -R "$_builddir"/doc/txt/* \
		"$subpkgdir"/usr/share/doc/$pkgname/txt/ || return 1

	# /usr/share/$pkgname
	mv "$pkgdir"/etc/pdnsd.conf.sample \
		"$subpkgdir"/usr/share/$pkgname/ || return 1
	_contribs="README change_pdnsd_server_ip.pl dhcp2pdnsd pdnsd_dhcp.pl"
	for _contrib in $_contribs; do
		cp -a "$_builddir"/contrib/$_contrib \
			"$subpkgdir"/usr/share/$pkgname/contrib/ || return 1
	done
        default_doc
}

sha512sums="4fde296642306aa986ddb7cad0b5991bcd397656d93ef4962706276848c7fa62c664a40198e807d029637f116e8000c237d98b91cbbfec5c08b134d8bb3adf81  pdnsd-1.2.9a-par.tar.gz
41062d23e4586a3db38609c808584e55d913786627a83cd7d4bf61ac963b4ad8ba4ea4316dc1839e5082cfe6e7c84cf4d0323da9380d3b6d29b7c870c1a7a156  pdnsd.initd
e8fc0667dd58a4bf6a685b9a6590fd5141e116ca7e769aa14180c642908fc214f3c3a6c45c7a3bb17f241bcb06ff6972ca46d1ab58e139ac9b68049fc137eadc  pdnsd.confd
ad023777f3d1f8eb5b9e296f42511c56aae4b5785b42a256c6f61d0b619657929622aced7034feabf321833e739a70c109610df0fc08e133557a7cf51c2fafd4  pdnsd.conf"
